<?php

use App\Core\Traits\Database\SchemaCommentTrait;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAttachmentsTable extends Migration
{
    use SchemaCommentTrait;

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('attachments', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('附件记录ID');
            $table->string('filename', 100)->nullable(false)->comment('附件名')->index();
            $table->string('storage_path', 100)->nullable(false)->comment('附件存储路径')->index();
            $table->bigInteger('size_byte')->comment('文件大小')->index();
            $table->string('size')->comment('文件大小,带单位(b,B,KB,MB,GB)');
            $table->string('file_type', 10)->comment('文件类型:enums:[doc,image,code,...]');
            $table->string('extension', 10)->comment('文件后缀名');
            $table->integer('duration')->nullable(true)->comment('时长');
            $table->string('uuid', 128)->comment('附件唯一ID');
            $table->string('refer_table', 50)->nullable(true)->comment('附件归属表');
            $table->bigInteger('refer_id')->default(0)->comment('附件归属表关联ID');
            $table->text('extras')->comment('附件相关配置');
            $table->smallInteger('state')->default(1)->comment('是否可用,enum:[-1:不可用,0:审核,1:正常可用,]')->index();
            $table->smallInteger('is_publish')->default(0)->comment('是否公开')->index();
            $table->dateTime('created_at')->nullable(false)->comment('创建时间');
            $table->dateTime('updated_at')->nullable(false)->comment('更新时间');
            $table->dateTime('deleted_at')->nullable(true)->comment('用户删除时间');
            $table->index(['refer_table', 'refer_id'], 'attachment_refer_uuid');
            $table->index(['file_type', 'extension'], 'attachment_type_id');
        });
        $this->comment('attachments', '平台附件记录表');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('attachments');
    }
}
